package com.itboye.sunsun.news;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;

import com.itboye.sunsun.R;
import com.itboye.sunsun.support.BaseActivity;
import com.sunsun.news.page.widget.PagerSlidingTabStrip;

public class NewsHotReadMainFragmentActivity extends BaseActivity {
	PagerSlidingTabStrip tabs;
	ViewPager pager;
	 
	NewsFragment bfrag;
	String[] titles = {  "时政要闻", "森森夜话", "休闲娱乐", "宠物世界", "周末走呗", "心灵微光"};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initView();
 
	}
	
	
	/**
	 * 返回上一级
	 */
	public void imgBack(View v){
		finish();
	}
	private void initView(){
		setContentView(R.layout.newsactivty);
		pager = (ViewPager) findViewById(R.id.pager);
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		pager.setAdapter(new MyAdapter(getSupportFragmentManager(),titles));
		tabs.setViewPager(pager);
		
		findViewById(R.id.back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}
	

	public class MyAdapter extends FragmentStatePagerAdapter{
		String[] _titles;
		public MyAdapter(FragmentManager fm,String[] titles) {
			super(fm);
			_titles=titles;
		}
		
		@Override
		public CharSequence getPageTitle(int position) {
			return _titles[position];
		}
		
		@Override
		public int getCount() {
			return _titles.length;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			// TODO Auto-generated method stub
//			super.destroyItem(container, position, object);
		}
		
		@Override
		public Fragment getItem(int position) {
			int id = 0;
			switch (position) {
			case 0:
				id = 6049;
				break;
			case 1:
				id = 6082;
				break;
			case 2:
				id = 6050;
				break;
			case 3:
				id = 6052;
				break;
			case 4:
				id = 6051;
				break;
			case 5:
				id = 6053;
				break;
			default:
				break;
			}
			NewsFragment bfrag2 = new NewsFragment(id);
				return bfrag2;
		}
	}
}
